/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.controller;

import java.util.List;

import com.comac.ins.common.core.domain.R;
import com.comac.ins.common.core.validate.AddGroup;
import com.comac.ins.common.core.validate.EditGroup;
import com.comac.ins.common.excel.utils.ExcelUtil;
import com.comac.ins.common.idempotent.annotation.RepeatSubmit;
import com.comac.ins.common.log.annotation.Log;
import com.comac.ins.common.log.enums.BusinessType;
import com.comac.ins.common.mybatis.core.page.PageQuery;
import com.comac.ins.common.mybatis.core.page.TableDataInfo;
import com.comac.ins.common.web.core.BaseController;
import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.comac.ins.isfd.domain.vo.IsfdDataUnitSystemManagementVo;
import com.comac.ins.isfd.domain.bo.IsfdDataUnitSystemManagementBo;
import com.comac.ins.isfd.service.IIsfdDataUnitSystemManagementService;

/**
 * 数据属性单位管理
 *
 * @author Lion Li
 * @date 2024-12-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/isfd/dataUnitSystemManagement")
public class IsfdDataUnitSystemManagementController extends BaseController {

    private final IIsfdDataUnitSystemManagementService isfdDataUnitSystemManagementService;

    /**
     * 查询数据属性单位管理列表
     */
    @SaCheckPermission("isfd:dataUnitSystemManagement:list")
    @GetMapping("/list")
    public TableDataInfo<IsfdDataUnitSystemManagementVo> list(IsfdDataUnitSystemManagementBo bo, PageQuery pageQuery) {
        return isfdDataUnitSystemManagementService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出数据属性单位管理列表
     */
    @SaCheckPermission("isfd:dataUnitSystemManagement:export")
    @Log(title = "数据属性单位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(IsfdDataUnitSystemManagementBo bo, HttpServletResponse response) {
        List<IsfdDataUnitSystemManagementVo> list = isfdDataUnitSystemManagementService.queryList(bo);
        ExcelUtil.exportExcel(list, "数据属性单位管理", IsfdDataUnitSystemManagementVo.class, response);
    }

    /**
     * 获取数据属性单位管理详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("isfd:dataUnitSystemManagement:query")
    @GetMapping("/{id}")
    public R<IsfdDataUnitSystemManagementVo> getInfo(@NotNull(message = "主键不能为空")
                                                     @PathVariable Long id) {
        return R.ok(isfdDataUnitSystemManagementService.queryById(id));
    }

    /**
     * 新增数据属性单位管理
     */
    @SaCheckPermission("isfd:dataUnitSystemManagement:add")
    @Log(title = "数据属性单位管理", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/add")
    public R<Integer> add(@Validated({AddGroup.class}) @RequestBody List<IsfdDataUnitSystemManagementBo> saveBos) {
        return R.ok(isfdDataUnitSystemManagementService.insertByBoList(saveBos));
    }

    /**
     * 修改数据属性单位管理
     */
    @SaCheckPermission("isfd:dataUnitSystemManagement:edit")
    @Log(title = "数据属性单位管理", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody IsfdDataUnitSystemManagementBo bo) {
        return toAjax(isfdDataUnitSystemManagementService.updateByBo(bo));
    }

    /**
     * 删除数据属性单位管理
     *
     * @param ids 主键串
     */
    @SaCheckPermission("isfd:dataUnitSystemManagement:remove")
    @Log(title = "数据属性单位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(isfdDataUnitSystemManagementService.deleteWithValidByIds(List.of(ids), true));
    }
}
